// Copyright 2022 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.mediapipe.tasks.text.textclassifier;

import com.google.auto.value.AutoValue;
import com.google.mediapipe.tasks.components.containers.ClassificationResult;
import com.google.mediapipe.tasks.components.containers.proto.ClassificationsProto;
import com.google.mediapipe.tasks.core.TaskResult;

/** Represents the classification results generated by {@link TextClassifier}. */
@AutoValue
public abstract class TextClassifierResult implements TaskResult {

  /**
   * Creates an {@link TextClassifierResult} instance.
   *
   * @param classificationResult the {@link ClassificationResult} object containing one set of
   *     results per classifier head.
   * @param timestampMs a timestamp for this result.
   */
  static TextClassifierResult create(ClassificationResult classificationResult, long timestampMs) {
    return new AutoValue_TextClassifierResult(classificationResult, timestampMs);
  }

  /**
   * Creates an {@link TextClassifierResult} instance from a {@link
   * ClassificationsProto.ClassificationResult} protobuf message.
   *
   * @param proto the {@link ClassificationsProto.ClassificationResult} protobuf message to convert.
   * @param timestampMs a timestamp for this result.
   */
  // TODO: consolidate output formats across platforms.
  static TextClassifierResult createFromProto(
      ClassificationsProto.ClassificationResult proto, long timestampMs) {
    return create(ClassificationResult.createFromProto(proto), timestampMs);
  }

  /** Contains one set of results per classifier head. */
  public abstract ClassificationResult classificationResult();

  @Override
  public abstract long timestampMs();
}
